﻿using AbpVnext_Module.Model;
using Ebusiness_Domain.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.PermissionManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement;
using Volo.Abp.Domain.Entities;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.AuditLogging;


namespace AbpVnext_Module.DBContext
{
    [ConnectionStringName("ProductImage")]
    public class ProductImageDbContext : AbpDbContext<ProductImageDbContext>
    {
        public ProductImageDbContext(DbContextOptions<ProductImageDbContext> options) : base(options)
        {

        }

        ///// <summary>
        ///// 配置日志是否显示
        ///// </summary>
        ///// <param name="optionsBuilder"></param>
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    //optionsBuilder.UseLoggerFactory(null);
        //    base.OnConfiguring(optionsBuilder);
        //}

        /// <summary>
        /// 配置商品图片模型
        /// </summary>
        //public DbSet<ProductImageOrder> ProductImageOrder { set; get; }

        //public DbSet<Product> products { set; get; }

        public DbSet<ProductImage>  productImages { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public DbSet<PermissionProduct> permissions { set; get; }

        /// <summary>
        /// 
        /// </summary>
        public DbSet<PermissionGrants> permissionGrants { set; get; }

        /// <summary>
        /// 在应用身份认证模块用户表基础上添加字段
        /// </summary>
        public DbSet<SysUser> sysUsers_Test { set; get; }

        //public DbSet<Zdf_test> zdf { get; set; }

        /// <summary>
        /// 重写方法
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            ////配置应用权限模块
            //模型表前缀
            //base.OnModelCreating(modelBuilder);

            ////配置应用权限模块
            //模型表前缀
            AbpPermissionManagementDbProperties.DbTablePrefix = "YDT_";
            modelBuilder.ConfigurePermissionManagement();

            //modelBuilder.Entity(delegate (EntityTypeBuilder<Zdf_test> b)
            //{
            //    b.ToTable(AbpPermissionManagementDbProperties.DbTablePrefix + "xxwwwwxxxxww", AbpPermissionManagementDbProperties.DbSchema);
            //    b.ConfigureByConvention();
            //    b.Property((Zdf_test x) => x.Id).HasMaxLength(PermissionDefinitionRecordConsts.MaxNameLength).IsRequired();
            //    b.Property((Zdf_test x) => x.name).HasMaxLength(PermissionGrantConsts.MaxProviderNameLength).IsRequired();
            //    b.ApplyObjectExtensionMappings();
            //});

            //可以在此处配置表别名
            //modelBuilder.Entity(delegate (EntityTypeBuilder<SysUser> b)
            //{
            //    b.ToTable(AbpPermissionManagementDbProperties.DbTablePrefix + "users", AbpPermissionManagementDbProperties.DbSchema);
            //});

            //配置应用身份认证模块
            //模型表前缀
            AbpIdentityDbProperties.DbTablePrefix = "YDT_";
            modelBuilder.ConfigureIdentity();

            //配置应用租户模块
            AbpTenantManagementDbProperties.DbTablePrefix = "YDT_";
            modelBuilder.ConfigureTenantManagement();

            //配置审计日志模块
            AbpAuditLoggingDbProperties.DbTablePrefix = "YDT_";
            modelBuilder.ConfigureAuditLogging();
        }
    }

    //[Table("Zdf_test")]
    //public class Zdf_test  :Entity<int>
    //{
    //    public string name { get; set; }
    //}
}
